#include<bits/stdc++.h>
using namespace std;
const int N = 12;

int arr[N][N];
int dp[N][N][N][N];
int n,x,y,num;

int mymax(int a,int b,int c,int d){
    return max(max(a,b),max(c,d));
}

int main()
{
    scanf("%d",&n);
    while(1){
        scanf("%d%d%d",&x,&y,&num);
        if(x==0&&y==0&&num==0) break;
        arr[x][y] = num;
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            for(int k=1;k<=n;k++){
                for(int l=1;l<=n;l++){
                    if(i+j==k+l){
                        dp[i][j][k][l] = mymax(
                            dp[i-1][j][k-1][l],dp[i-1][j][k][l-1],
                            dp[i][j-1][k-1][l],dp[i][j-1][k][l-1]
                        )+arr[i][j]+arr[k][l];
                        if(i==k&&j==l) dp[i][j][k][l] -= arr[k][l];
                    }
                }
            }
        }
    }
    printf("%d\n",dp[n][n][n][n]);
    return 0;
}